package br.com.absolutech.study.chapter6.pag251;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 
 * @author romulo.freitas
 * 
 * example for java 1.4
 *
 */
public class Main {

	public static void main(String[] args) {

		try {

			File file = new File("resources/fileWrite2-2.txt");
			if (!file.exists()) {
				FileWriter fw;
				fw = new FileWriter(file);
				PrintWriter pw = new PrintWriter(fw);
				pw.println("howdy");
				pw.println("folks");
				pw.flush();
				pw.close();
			}

			FileReader fr = new FileReader(file);
			BufferedReader br = new BufferedReader(fr);

			String data = "";
			for (data = br.readLine(); data != null; data = br.readLine()) {
				System.out.println(data);
			}
			br.close();

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
